package com.example.demo.LeetCode.arr;

public class RemoveItem {

    public static int remove(int[] nums,int target){
        int size = nums.length;
        for (int  i =0;i < size; i++){
            if (nums[i] == target){
                for (int j = i+1 ; j < size; j++ ){
                    //往前移动
                    nums[j-1] = nums[j];
                }
                // 因为下标i以后的数值都向前移动了一位，i也需要往前移动
                i--;
                size--;
            }
        }
        return  size;
    }

    public static void main(String[] args) {
        int[] nums = {0,1,2,3,3,0,4,2};
        int target = 2;
        System.out.println(remove(nums,target));
    }
}
